////////////////////////////////////////////////////////////////////////////////
//
//  FLYING KIWI BV
//  Copyright 2010 Flying Kiwi BV
//  All Rights Reserved.
//
//  NOTICE: Flying Kiwi permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package plantool.modules.menu.display {
	//--------------------------------------------------------------------------
	//  Imports
	//--------------------------------------------------------------------------
	import flash.events.MouseEvent;
	
	import kiwi.components.Button;
	import kiwi.events.CallbackEvent;
	
	import plantool.core.CoreDisplayObject;
	import plantool.modules.menu.data.MenuItemData;
	
	
	//--------------------------------------------------------------------------
	//  [Metadata (Events, Style, Effects etc)]
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//  Class declaration
	//--------------------------------------------------------------------------
	public class MenuItem extends CoreDisplayObject {
		//--------------------------------------------------------------------------
		//Class constants
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//Class variables
		//--------------------------------------------------------------------------
		private var _itemData:MenuItemData	= null;
		private var _hotspot:Button			= new Button();
		
		//--------------------------------------------------------------------------
		//Class properties
		//--------------------------------------------------------------------------
		public function get itemData():MenuItemData {
			return _itemData;
		}
		public function set itemData(value:MenuItemData):void {
			//set itemData
			_itemData = value;
			
			//set hotspot test
			_hotspot.text = _itemData.title;
		}

		public override function get height():Number {
			return _hotspot.height;
		}
		public override function set height(value:Number):void {
			//set width
			_hotspot.height = value;
		}

		public override function get width():Number {
			return _hotspot.width;
		}
		public override function set width(value:Number):void {
			//set width
			_hotspot.height = value;
		}
		
		//--------------------------------------------------------------------------
		//Constructor and Destructor
		//--------------------------------------------------------------------------
		public function MenuItem(item:MenuItemData) {
			_itemData = item;
			super();
		}
		
		//--------------------------------------------------------------------------
		//Class methods
		//--------------------------------------------------------------------------
		private function hotspotMouseHandler(e:CallbackEvent):void {
			switch ((e.userData as MouseEvent).type) {
				case MouseEvent.CLICK:
					_itemData.callback();
					break;
			}
		}
		
		protected override function init():void {
			//create textfield
			_hotspot.skin			= new MenuItemButtonSkin();
			_hotspot.mouseHandler	= hotspotMouseHandler;
			_hotspot.width			= 150;
			_hotspot.height			= 22;
			_hotspot.text 			= _itemData.title;
			addChild(_hotspot);
			
			//call super init
			super.init();
		}
	}
}